﻿package org.hsl.avm2.translation.progress;
import flash.events.ProgressEvent;
import org.hsl.haxe.translation.ITranslator;
import org.hsl.haxe.translation.NativeEvent;
/**
 * A translator that translates progress events to load progresses.
 */
// Ideally, the following line would be:
// class LoadProgressTranslator implements ITranslator<LoadProgress> {
// However, that doesn't work targetingAVM2.
class LoadProgressTranslator<D> implements ITranslator<D> {
	/**
	 * Creates a load progress translator.
	 */
	public function new():Void {
	}
	public function translate(nativeEvent:NativeEvent):D {
		var progressEvent:ProgressEvent;
		try {
			progressEvent = cast(nativeEvent, ProgressEvent);
		} catch (error:Dynamic) {
			throw "The nativeEvent argument must be a ProgressEvent.";
		}
		return untyped new LoadProgress(progressEvent.bytesLoaded, progressEvent.bytesTotal);
	}
}